<cc:page type="sitepage" style="standard" showSidebar="false" showHeader="false" />

<cc>
    {


    //这是一个Site页面，可以通过URL直接访问 上面是测试环境
    //ServiceResult sr = CCService.getUserInfo("61ee0c8c32fe6ea38850a3475fa15750fbc1bb1a20768b71", "test_hhtest@cloudcc.com", "111111");
    ServiceResult sr = CCService.getUserInfo("f6c729c175119d3aa2942d814a63df8564dfe85e8959db2d", "interface@cloudcc.com", "111111");
    //        ServiceResult sr = null;
    UserInfo uuserInfo = (UserInfo) sr.get("COMMON_USERINFO");
    java.util.Date date = new java.util.Date();
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String startTime = sdf.format(date);
    CCService service = new CCService(uuserInfo);
    String JD_LOST="5-丢单";
    String msg = "{\"code:\",\"1\"}";
    String data = request.getParameter("data") == null ? "" : request.getParameter("data") + "";
    /*调用链id*/
    String invokeId = request.getParameter("invokeId") == null ? "" : request.getParameter("invokeId");
    /*接口名称*/
    String name = request.getParameter("name") == null ? "" : request.getParameter("name");
    try {
    /*数据*/

    /*数据转json数据,方便获取git*/
    net.sf.json.JSONObject fromData = null;
    String notifyType = "";
    String scode = "";
    String returnInfo = "";
    try {
    fromData = net.sf.json.JSONObject.fromObject(data);
    /*客户开函或者客户开户、通知类型*/
    notifyType = fromData.get("notifyType") == null ? "" : fromData.get("notifyType") + "";
    /*社会信用统一代码*/
    scode = fromData.get("cusCertNo") == null ? "" : fromData.get("cusCertNo") + "";
    } catch (Exception e) {
    }

    /*客户的记录类型,电子保函客户*/
    String recordType_test = "202385551266A597FF1B";
   // String recordType_test = "20211C59581DC5CZOn5N";

    /*正常情况下的响应代码*/
    String resultCode = "0000";

    String findAccountSql = "SELECT id FROM Account where is_deleted ='0' ";
    String findEleoppSql = "SELECT * FROM eleopp where is_deleted ='0'";

    String findEleoppInfoSql= "";
    /*客户开户请求*/
    if (notifyType.equals("openacc")) {
    CCObject interface_record = new CCObject("interface_record");
    interface_record.put("record_ID", invokeId);
    interface_record.put("url", "crm/rgmOpening");
    interface_record.put("requestDataLong", name);
    interface_record.put("datas", data);
    service.insert(interface_record);
    /*查询客户是否存在商机*/
    String sql = findAccountSql + " and invoiceTaxNo ='" + scode + "'";
    List<CCObject> accountList = service.cqlQuery("Account", sql);
    if (accountList.size() > 0 && accountList != null) {
    String accountId = accountList.get(0).get("id") + "";
    findEleoppInfoSql = findEleoppSql + " and khmc ='" + accountId + "' and jieduan !='"+JD_LOST+"'";
    /*通过客户获取商机 更改商机阶段*/
    List<CCObject> eleoppInfo = service.cqlQuery("eleopp", findEleoppInfoSql);
        if (eleoppInfo.size() > 0) {
        String updateAccountType = "update Account set recordtype='" + recordType_test + "' where id ='" + accountId + "'";
        service.cqlQuery("Account", updateAccountType);

        /*查询会员信息*/
        com.cloudcc.core.fag.CCUST_191127DFDFD896.EleQueryCustomer2 eqc2 = new  com.cloudcc.core.fag.CCUST_191127DFDFD896.EleQueryCustomer2(uuserInfo);
        net.sf.json.JSONObject params = new net.sf.json.JSONObject();
        net.sf.json.JSONObject dataInfo = new net.sf.json.JSONObject();
        params.put("invokeId", "");
        dataInfo.put("cusCertType", "1");
        dataInfo.put("cusCertNo", scode);
        params.put("data", dataInfo);
        String rs = eqc2.sendPost("", params.toString());
        CCObject interface_record1 = new CCObject("interface_record");
        interface_record1.put("datas", params);
        interface_record1.put("url", "EleQueryCustomer");
        interface_record1.put("requestDataLong", rs);
        service.insert(interface_record1);
        net.sf.json.JSONObject result = net.sf.json.JSONObject.fromObject(rs);
        String resultCodeA = result.getString("resultCode");
        String RCODE = "0000";
        String source = "";
        if (resultCodeA.equals(RCODE)){
        net.sf.json.JSONObject info = result.getJSONObject("data");
        if (!info.isNullObject()) {
        String cusSource = info.get("cusSource") == null ? "" : info.get("cusSource") + "";
        String createTime = info.get("createTime") == null ? "" : info.get("createTime") + "";

        String findSource = "select fy from zcly where name ='"+cusSource+"' and is_deleted='0' " ;

        List<CCObject> zcly = service.cqlQuery("zcly", findSource);
            if (zcly.size()>0){
            source = zcly.get(0).get("fy")==null?"":zcly.get(0).get("fy")+"";
            }
            }
            }


            String updateEleoppSql="update eleopp set accountTime='"+startTime+"',source='"+source+"' where is_deleted='0' and khmc ='" + accountId + "' and jieduan !='"+JD_LOST+"'";
            service.cqlQuery("eleopp", updateEleoppSql);
            }
            }
            }



            net.sf.json.JSONObject result = new net.sf.json.JSONObject();//Json对象
            result.put("invokeId", invokeId);
            result.put("resultCode", resultCode);
            result.put("resultMessage", "SUCCESS");
            result.put("data", fromData);
            msg = String.valueOf(result);

            } catch (Exception e) {
            CCObject object = new CCObject("exceptionInfo");
            object.put("exception", "客户开户开函接口异常：" + e);
            msg=e.toString();
            }
            request.setAttribute("jsonmsg", msg);



            }


</cc>
<cc:forward page="/platform/activity/task/getNodes.jsp">
    <cc:param name="jsonmsg" value="" />
</cc:forward>
